﻿using System;
using System.Collections.Generic;
using System.Text;
using Pixysoft.Framework.Reflection;
using Pixysoft.Weblications.Sango.Dao;
using Pixysoft.Weblications.Sango.Protocol.player;
using Pixysoft.Weblications.Sango.Protocol;
using Pixysoft.Weblications.Sango.Formular;

namespace Pixysoft.Weblications.Sango.Command.pvp_resource
{
    partial class SangoPvpResourceHandler
    {
        public pvpresource_abandon pvpresource_abandon(string primarycode)
        {
            string userCode = SangoManager.Authentication();

            pvpresource_abandon response = ReflectionManager.CreatePojo<pvpresource_abandon>();
            response.Succeed = false;

            Entities.Usr_Profile profile = UsrProfileDao.getUsrProfile(userCode);

            Entities.Usr_Resource resource = UsrResourceDao.TryGetResource(primarycode, userCode);

            if (resource == null)
            {
                response.Message = "无法结算";
                return response;
            }

            ResourceFormular.resourceCurrentBalance(resource, profile);

            IEntityNoebeTransaction command = SettingHelper.EntityTransaction;

            command.Begin(delegate()
            {
                command.Update(profile);

                command.Update(resource);

                command.Commit();
            });

            response.profile = UsrProfileFacade.ToProfile(profile);
            response.Succeed = true;
            return response;
        }


    }
    public interface pvpresource_abandon : ISangoResponse
    {
        player_profile profile { get;set;}
    }
}
